#ifndef _LINEARBUFFER_H_
#define _LINEARBUFFER_H_

namespace utillib
{
	namespace memory
	{
			class LinearBuffer
			{
			public:
				LinearBuffer(size_t size = 0, bool resizable = false );
				~LinearBuffer();

				void initialize(size_t size);

			protected:
				bool resize(size_t size);
				void realignBuffer();

			public:
				bool resize();

				unsigned char *endOfBuffer();
				unsigned char *beginOfBuffer();

				void resetOffset();
				size_t offset(size_t offset);
				size_t offset();

				void resetBufferSize();
				size_t bufferSize();
				size_t bufferSize(size_t size);

				size_t remainSize();

				size_t arrangeOffset(size_t size);

				bool reserveBuffer(size_t size);

				unsigned char *read(unsigned char *ptr, size_t size);
				unsigned char *write(const unsigned char *ptr, size_t size);

				void reset();
				size_t capacity();

			private:
				void release();

				unsigned char *m_buffer;
				size_t m_usingBufferSize;
				size_t m_bufferCapacity;
				size_t m_beginOffset;
				bool m_resizable;
			};
	}
}

#endif
